package com.cloud.redis7.utils;

import com.cloud.redis7.entities.Customer;
import com.cloud.redis7.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.EntityTable;
import tk.mybatis.mapper.mapperhelper.EntityHelper;

import javax.annotation.Resource;
import java.util.Arrays;

//@Component
public class KeyCheck implements CommandLineRunner {

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public void run(String... args) throws Exception {
        try {
            // 获取实体类元数据
            EntityTable entityTable = EntityHelper.getEntityTable(Customer.class);
            System.out.println("主键列: " + Arrays.toString(entityTable.getKeyColumns()));
            System.out.println("主键属性: " + Arrays.toString(entityTable.getKeyProperties()));

            // 测试查询
            Customer customer = customerMapper.selectByPrimaryKey(20);
            System.out.println("查询结果: " + customer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}